package com.dayilyword.config.resultFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;

/**
 * <p>>@作者 Sc
 * <p>>@所属包 dayilyword:com.dayilyword.config
 * <p>>@创建时间 2020-11-17-18-04
 * <p>>@功能描述
 **/
public class ResultFormat {
    @Autowired
    private static MessageSource messageSource;

    /**
     * 成功 返回空
     *
     * @return
     */
    public static Result okRNull() {
        return formatResult(ResultEnum.SUCCESS, null);
    }

    /**
     * 成功返回body
     *
     * @param data
     * @return
     */
    public static Result ok(Object data) {
        return formatResult(ResultEnum.SUCCESS, data);
    }

    public static Result formatResult(ResultEnum resultEnum, Object data) {
        Result result = new Result(resultEnum, data);
        result.setMsg(resultEnum.getName(resultEnum.getCode()));
        return result;
    }



}
